package com.springboot.husha.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.springboot.husha.entity.Fenggedashan;
import com.springboot.husha.entity.Zhenshikezhao;
import com.springboot.husha.mapper.FenggedashanMapper;
import com.springboot.husha.qpage.QPage;
import com.springboot.husha.service.IFenggedashanService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.springboot.husha.util.Result;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;

/**
 * <p>
 * 风格大赏 服务实现类
 * </p>
 *
 * @author author
 * @since 2024-02-28
 */
@Service
public class FenggedashanServiceImpl extends ServiceImpl<FenggedashanMapper, Fenggedashan> implements IFenggedashanService {


    /**
     * 分页查询
     * @param qPage
     * @return
     */
    @Override
    public IPage getPageList(QPage qPage, Fenggedashan obj) {
        IPage iPage = new Page(qPage.getPage(), qPage.getRows());
        QueryWrapper<Fenggedashan> queryWrapper=new QueryWrapper<Fenggedashan>();
        if(!StringUtils.isEmpty(obj.getName())){
            queryWrapper.like("name",obj.getName());
        }
        queryWrapper.orderByDesc("ctime");
        IPage mapList =this.page(iPage,queryWrapper);
        return mapList;
    }

    /**
     * 新增
     * @param obj
     * @return
     */
    @Override
    public Result insert(Fenggedashan obj) {
        obj.setCtime(new Date());
        if(this.save(obj)){
            return Result.reOk("恭喜，新增成功");
        }
        return Result.reError("新增出错");
    }

    /**
     * 修改
     * @param obj
     * @return
     */
    @Override
    public Result updates(Fenggedashan obj) {
        obj.setUtime(new Date());
        if(this.updateById(obj)){
            return Result.reOk("恭喜，修改成功");
        }
        return Result.reError("修改出错");
    }


}
